#!/usr/bin/env python3



from time import time

def euler81():
  """
  Find the minimal path sum, in matrix.txt (right click and 'Save Link/Target As...'), a 31K text file containing a 80 by 80 matrix, from the top left to the bottom right by only moving right and down.
  """
  matrix = []
  with open("matrix.txt") as file:
    for line in file.readlines():
      matrix.append(list(map(lambda x: int(x),line.strip().split(","))))
  len_matrix = len(matrix)
  for i in range(1,len_matrix):
    matrix[0][i] += matrix[0][i-1]
    matrix[i][0] += matrix[i-1][0]
  for i in range(1,len_matrix):
    for j in range(1,len_matrix):
      matrix[i][j] += min(matrix[i-1][j],matrix[i][j-1])
  return matrix[-1][-1]

"""
Print answer and process time
"""
if __name__=="__main__":
  time_begin = time()
  print("Answer : {}".format(euler81()))
  print("Time : {}\"".format(time()-time_begin))
